local lishi = fk.CreateSkill{
  name = "wk_heg__lishi",
  tags = {Skill.DeputyPlace},
}

Fk:loadTranslationTable{
  ["wk_heg__lishi"] = "励势",
  [":wk_heg__lishi"] = "副将技，其他角色的结束阶段，你可令一名本回合受到过伤害的与你势力相同的角色选择复原武将牌或使用一张牌。",
  ["wk_heg__lishi_pro"] = "励势：选择一名本回合受到过伤害的角色复原武将牌或使用一张牌",
  ["#wk_heg__lishi_use"] = "励势：你可以使用一张牌，或点“取消”复原武将牌",
 
  ["$wk_heg__lishi1"] = "敌军围困万千重，我自岿然不动。。",
  ["$wk_heg__lishi2"] = "行伍严整，百战不殆。",
}

local H = require "packages/ol_hegemony/util"

lishi:addEffect(fk.EventPhaseStart, {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    if not (player:hasSkill(self) and target ~= player and target.phase == Player.Finish) then return false end 
    local targets = {}
    player.room.logic:getActualDamageEvents(1, function(e)
      local damage = e.data
      if H.compareKingdomWith(player, damage.to) then
        table.insertIfNeed(targets, damage.to)
      end
      return false
    end)
    if #targets > 0 then
      event:setCostData(self, {targets = targets})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = event:getCostData(self).targets
    local tos = room:askToChoosePlayers(player, {
        targets = targets,
        min_num = 1,
        max_num = 1,
        prompt = "wk_heg__lishi_pro",
        skill_name = lishi.name,
        cancelable = true,
      })
    if tos then
      local to = tos[1]
      local use = room:askToPlayCard(to, {
        skill_name = lishi.name,
        prompt = "#wk_heg__lishi_use",
        cancelable = true,
        extra_data = {
          bypass_times = true,
          extraUse = true,
        },
        skip = true,
      })
      if use then
        room:useCard(use)
      else
        to:reset()
      end
    end
  end,
})

return lishi